import MathUtil from '@/MathUtil';
import MovementCommon from 'code/Core/Common/MovementCommon';
import TalentBase from 'code/Scripts/Abilities/base/TalentBase';
const desc = `被动增加${ColorSafe}200|r射程,当敌人与你的距离超过${ColorSafe}400|r码，你与敌人间的距离每超过${ColorSafe}10|r码则攻击伤害提升${ColorSafe}1%|r。但是如果小于400码则减少${ColorDanger}30%|r。觉醒：攻击与你距离小于${ColorSafe}400|r码的敌人则利用强大的后座力后退到${ColorSafe}400|r码之外`;
const art = 'ReplaceableTextures\\CommandButtons\\BTNDwarvenLongRifle.blp';
const name = '狙击枪';
const config: TalentConfigModel = {
    id: 'talent_t_TalentSniperGun',
    name,
    desc,
    art,
    buffType: {
        id: 'buff_t_TalentSniperGun',
        art,
        name,
        ubertip: desc,
        attribute: {
            damage_range: 200,
        },
    },
    buffTypePlus: {
        id: 'buff_t_TalentSniperGun_plus',
        art,
        name: '狙击枪[觉醒]',
        ubertip: `被动增加${ColorSafe}200|r射程,当敌人与你的距离超过${ColorSafe}400|r码，你与敌人间的距离每超过${ColorSafe}10|r码则攻击伤害提升${ColorSafe}1%|r。但是如果小于400码则减少${ColorDanger}30%|r。且在攻击与你距离小于${ColorSafe}400|r码的敌人则利用强大的后座力后退到${ColorSafe}400|r码之外`,
        attribute: {
            damage_range: 200,
        },
    },
};
export default class TalentSniperGun extends TalentBase {
    static instance: TalentSniperGun;
    onBuffEnd(p: HitFlyConfig<effect>) {
        DestroyEffect(p.other);
    }
    constructor(p?: TalentConfigModel) {
        super(p);
        TalentSniperGun.instance = this;
        this.setTalentConfig(config);
        EventManager.onBeforApplyAttack(this.attackEffect);
    }
    attackEffect(d: DamageEventData) {
        let _this = TalentSniperGun.instance;
        let { unEffect, plus } = _this.talentUnEffect(d.source);
        if (unEffect) return;
        let dis = MathUtil.distanceBetweenUnits(d.source, d.target);
        if (dis > 100) {
            d.initDamage *= (dis - 400) / 1000 + 1;
        } else {
            d.initDamage *= 0.7;
            if (plus) {
                let distance = 400 - dis;
                let ef = AddSpecialEffectTarget('Abilities\\Weapons\\TreantMissile\\TreantMissile.mdl', d.source, 'origin');
                MovementCommon.hitFly({
                    target: d.source,
                    caster: d.source,
                    distance,
                    angle: GetUnitFacing(d.source) + 180,
                    speed: 1200,
                    maxHeight: 0,
                    other: ef,
                    onEnd: _this.onBuffEnd,
                });
            }
        }
    }
}
